package models

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type CommentListResponse struct {
	Response
	CommentList []Comment `json:"comment_list,omitempty"`
}

func CommentListSuccess(c *gin.Context, commentList []Comment) {
	c.JSON(http.StatusOK, &CommentListResponse{
		Response:    Response{StatusCode: CodeSuccess, StatusMsg: ResCode.Msg(CodeSuccess)},
		CommentList: commentList,
	})
}

func CommentListError(c *gin.Context, code ResCode) {
	c.JSON(http.StatusOK, &CommentListResponse{
		Response:    Response{StatusCode: code, StatusMsg: code.Msg()},
		CommentList: []Comment{},
	})
}

type CommentRequest struct {
	VideoId     int64  `form:"video_id" json:"video_id" binding:"required"`
	ActionType  int32  `form:"action_type" json:"action_type" binding:"required"`
	CommentText string `form:"comment_text" json:"comment_text"`
	CommentId   int64  `form:"comment_id" json:"comment_id"`
}

type CommentListRequest struct {
	VideoId int64 `form:"video_id" json:"video_id" binding:"required"`
}

type CommentatorResult struct {
	CommentId int64
	UserId    int64
}

type Commentator struct {
	VideoId    int64 `gorm:"primaryKey;autoIncrement:false"`
	UserId     int64 `gorm:"primaryKey;autoIncrement:false"`
	CommentId  int64 `gorm:"primaryKey;autoIncrement:false"`
	CreateTime int64 `gorm:"autoCreateTime"`
}

// 一个人可以给一个视频，评论多条
// 评论是不会经常删除的，点赞和关注是有可能经常变动的
/**
1) 用户1评论视频2，评论帖子为3
	1.创建一贴评论，commentId
	2.维护 comment_count
	3.insert into CommentRelation(userId,videoId,commentId) values(1,2,3)
2) 视频3的所有评论：
	select commentId from CommentRelation where videoId =3 ORDER BY CreateTime DESC
*/
